import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state={
  type:[],//所有的商品种类集合
  wareslist:[],//所有的商品集合
  cartlist: [], //存放购物的商品集合
  paylist:[],//存放待支付的商品集合
  videolist:[],//存放美食视频集合
  tempAddress:null,//临时存储添加的地址
  hotproduct:[],//热门商品
  commonAddress:[],//存储的真实地址
  currentAddress:"",//当前地址
  userInfo:{},//用户登录信息
}

const getters={
  type:state=>state.type, 
  wareslist:state=>state.wareslist,
  cartlist:state=>state.cartlist,
  paylist:state=>state.paylist,
  videolist:state=>state.videolist,
  tempAddress:state=>state.tempAddress,
  commonAddress:state=>state.commonAddress,
  hotproduct:state=>state.hotproduct,
  currentAddress:state=>state.currentAddress,
  userInfo:state => state.userInfo,
}

const mutations={
  todotype(state,type){
     state.type=type;
  },
  todowareslist(state,wareslist){
    state.wareslist=wareslist;
  },
  todocartlist(state,cartlist){
    state.cartlist=cartlist;
  },
  todopaylist(state,paylist){
    state.paylist=paylist;
  },
  todovideolist(state,videolist){
    state.videolist=videolist;
  },
  setTempAddress(state,tempAddress){
    state.tempAddress=tempAddress;
  },
  setCommonAddress(state,newAddress){
    state.commonAddress.push(newAddress);
  },
  setHotProduct(state,hotproduct){
    state.hotproduct=hotproduct;
  },
  setCurrentAddress(state,currentAddress){
    state.currentAddress = currentAddress;
  },
  setUserInfo(state,userInfo){
    state.userInfo = userInfo ? userInfo : null;
  },
  setAccountData(state,accountData){
    state.accountData = accountData;
  },
  setphoneData(state,phoneData){
    state.phoneData = phoneData;
  },
}

const actions={
  todotype({commit},type){
    commit("todotype",type);
  },
  todowareslist({commit},wareslist){
    commit("todowareslist",wareslist)
  },
  todocartlist({commit},cartlist){
    commit("todocartlist",cartlist)
  },
  todopaylist({commit},paylist){
    commit("todopaylist",paylist)
  },
  todovideolist({commit},videolist){
    commit("todovideolist",videolist)
  },
  setTempAddress({commit},tempAddress){
    commit('setTempAddress',tempAddress);
 },
 setCommonAddress({commit},newAddress){
   commit('setCommonAddress',newAddress);
 },
 setHotProduct({commit},hotproduct){
   commit('setHotProduct',hotproduct);
 },
 setCurrentAddress({commit},currentAddress){
   commit('setCurrentAddress',currentAddress);
 },
 setUserInfo({commit},userInfo){
  commit('setUserInfo',userInfo)
},
setAccountData({commit},accountData){
  commit('setAccountdata',accountData)
},
setphoneData({commit},phoneData){
  commit('setphoneData',phoneData)
},
}
export default new Vuex.Store({
  state,
  mutations,
  actions,
  getters
})
